import java.sql.Connection
import java.sql.SQLException

import org.apache.commons.dbcp2.BasicDataSource
import org.apache.commons.dbcp2.BasicDataSourceFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class DbcpHelper {

	private static final Logger log = LoggerFactory.getLogger(DbcpHelper.class)
	static BasicDataSource ds

	static{
		def inStream = DbcpHelper.class.getResourceAsStream("/dbcp-config.properties");
		def prop=new Properties(); 
        try { 
            prop.load(inStream);
			ds=(BasicDataSource) BasicDataSourceFactory.createDataSource(prop);
		} catch (e) {
			throw new ExceptionInInitializerError("初始化数据库出错！");
			log.info(e.toString())
		}
	}
	
	static Connection getConnection() throws SQLException {
		ds.getConnection()
	}
	
	static main(args) {
		println getConnection()
	}

}
